﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
    <title>修改密码</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="style/adminStyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="wrap">
    <div class="page-title">
        <span class="modular fl"><i class="user"></i><em>修改密码</em></span>
    </div>
    <table class="noborder">
        <tr>
            <td width="15%" style="text-align:right;">账号：</td>
            <td><input type="text" value="${sessionScope.user_name}" class="textBox length-middle"/></td>
        </tr>
        <tr>
            <td style="text-align:right;">邮箱：</td>
            <td><input type="text" value="${sessionScope.email}" class="textBox length-middle"/></td>
        </tr>
        <tr>
            <td style="text-align:right;">旧密码：</td>
            <td><input id="password1" type="password" class="textBox length-middle"/></td>
        </tr>
        <tr>
            <td style="text-align:right;">新密码：</td>
            <td><input id="password2" type="password" class="textBox length-middle"/></td>
        </tr>
        <tr>
            <td style="text-align:right;">再次确认密码：</td>
            <td><input id="password3" type="password" class="textBox length-middle"/></td>
        </tr>
        <tr>
            <td style="text-align:right;"></td>
            <td><input type="button" id="btn_update" class="tdBtn" value="保存"/></td>
        </tr>
    </table>
</div>
<script src="js/jquery.js"></script>
<script src="js/Particleground.js"></script>
<script type="text/javascript">
    $(function () {
        $("#btn_update").click(function () {
            var p1 = $("#password1").val();
            var p2 = $("#password2").val();
            var p3 = $("#password3").val();
            if (p1 === p2) {
                alert("旧密码和新密码相同")
            } else {
                if (p2 === p3) {
                    //更改密码
                    $.ajax({
                        type: "post",
                        url: "/cai/updatePassword",
                        data: {
                            password: $("#password2").val()
                        },
                        success: function (data) {
                            if (parseInt(data) === 1) {
                                alert("更改成功！")
                            } else {
                                alert("更改失败！")
                            }
                        },
                        error: function (data) {
                            alert("更改出错")
                            console.log(data)
                        }
                    })
                } else {
                    alert("新密码输入不一致");
                }
            }
        })
    })
</script>
</body>
</html>